Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(wren-ai-service): sql2answer-minor-update #691

Merged
merged 4 commits into from
Oct 2, 2024

Conversation

cyyeh
Copy link
Member

@cyyeh cyyeh commented Oct 1, 2024

allow auto-refresh expired vertexai credentials

@cyyeh cyyeh added module/ai-service ai-service related ci/ai-service ai-service related labels Oct 1, 2024
@cyyeh cyyeh requested a review from paopa October 1, 2024 06:55
Comment on lines 62 to 81
# check if the model is actually Vertex AI model
self._vertexai_creds = None
if model.startswith("google/"):
self._vertexai_creds, _ = google.auth.default(
scopes=["https://www.googleapis.com/auth/cloud-platform"]
)

def __getattr__(self, name: str) -> Any:
# dealing with auto-refreshing expired credential
# https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/call-vertex-using-openai-library#refresh_your_credentials
if self._vertexai_creds and not self._vertexai_creds.valid:
auth_req = google.auth.transport.requests.Request()
self._vertexai_creds.refresh(auth_req)

if not self._vertexai_creds.valid:
raise RuntimeError("Unable to refresh auth")

self.client.api_key = self._vertexai_creds.token
return getattr(self.client, name)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit curious, why did we validate the credit of vertexai in the openai provider?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left comment

@cyyeh cyyeh merged commit 6104776 into main Oct 2, 2024
7 checks passed
@cyyeh cyyeh deleted the chore/ai-service/sql2answer-update branch October 2, 2024 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci/ai-service ai-service related module/ai-service ai-service related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants